package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;

@Getter@Setter
public class StrategyDetail extends BaseDomain{
    public static final Integer STATE_RELEASE = 1;//已发布
    public static final Integer STATE_AUDIT = 0;//草稿
    public static final Integer STATE_DISABLE = -1;//禁用
    private String title;

    private Date createTime;

    private Date releaseTime;

    private Integer sequence;

    private StrategyCatalog catalog;

    private String coverUrl;

    private Integer state;

    private StrategyContent content;

    public String getStateName(){
        String msg = "草稿";
        if(STATE_RELEASE==state){
            msg = "已发布";
        }else if(STATE_DISABLE ==state){
            msg = "禁用";
        }
        return msg;
    }

    public String getJson(){
        HashMap map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("sequence",sequence);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        map.put("releaseTime", DateUtil.formatDate(releaseTime));

        if(catalog!=null){
            map.put("catalogId",catalog.id);
            map.put("catalogName",catalog.getName());
            if(catalog.getStrategy()!=null){
                map.put("StrategyId",catalog.getStrategy().id);
            }
        }
        return JSONUtil.toJSONString(map);
    }
}